/*=============================================================================
*
*   Copyright (C) 2020 All rights reserved.
*
*   Filename:		linear_tfunction.hpp
*
*   Author: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Date: 2020-03-04 15:00
*
*   Last Editors: Wang Zhecheng - wangzhecheng@yeah.net
*
*   Last modified:	2020-03-23 15:25
*
*   Description:
*
=============================================================================*/
#ifndef LINEAR_TFUNCTION_H
#define LINEAR_TFUNCTION_H

#include "time_function_interface.hpp"

namespace geoxfem {
namespace arithmetic {

struct Linear_Function : Time_Function_Interface {
  DEFINE_KEY(Linear_Function)

  Linear_Function();
  Linear_Function(const ptree& data, const _real& t0, const _real& t1);
  ~Linear_Function();

  _real getValueAt(const _real& time) const final override;

private:
  _real m_v0;
  _real m_v1;
};

Linear_Function::Linear_Function() = default;

Linear_Function::Linear_Function(const ptree& data,
                                 const _real& t0,
                                 const _real& t1)
    : Time_Function_Interface{data, t0, t1},
      m_v0{data.get("start", _real(0))},
      m_v1{data.get("end", _real(0))} {}

Linear_Function::~Linear_Function() = default;

_real Linear_Function::getValueAt(const _real& time) const {
  return m_v0 + (m_v1 - m_v0) * (time - m_t0) / (m_t1 - m_t0);
}

}  // namespace arithmetic
}  // namespace geoxfem

#endif /* LINEAR_TFUNCTION_H */
